#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
#include <unistd.h>
#include <unistd.h>

int main()
{
    //有点像就近原则
    umask(0);

    //fopen("log.txt", "w"); //底层的调用的是open, O_WRONLY | O_CREAT | O_TRUN和这些选项，还要设置属性
    int fd = open("log.txt", O_WRONLY | O_CREAT | O_TRUNC, 0666);
    if(fd < 0)
    {
        perror("open");

        return 1;
    }

    printf("fd : %d\n", fd);

    int cnt = 0;
    //const char* str = "Hello World\n";
    const char* str = "aaa";
    while(cnt < 2)
    {
        //不能带\0,这是C语言的用法, 文件不认识\0
        write(fd, str, strlen(str));
        cnt++;
    }

    return 0;
}

